<template>
  <div class="app-container">
    <!-- 查询 -->
    <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" :isDisplaySearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <el-form-item label="项目名称(新)">
          <el-input v-model="queryParam.qry_name2" @change="changename2"></el-input>
        </el-form-item>
        <el-form-item label="项目经理(新)">
          <el-input v-model="queryParam.qry_projectmanagername2" @change="changeprojectmanagername2"></el-input>
        </el-form-item>
        <!-- <el-form-item label="申请人">
          <el-input v-model="queryParam.qry_user" placeholder=""></el-input>
        </el-form-item> -->
        <el-form-item label="单据编号">
          <el-input v-model="queryParam.qry_docno" placeholder="" @change="changedocno"></el-input>
        </el-form-item>
        <!-- <el-form-item label="单据日期" prop="qry_begindocdate">
          <el-date-picker v-model="queryParam.qry_begindocdate" type="date" style="width:140px" value-format="yyyy-MM-dd" placeholder="开始时间" />至
          <el-date-picker v-model="queryParam.qry_enddocdate" type="date" style="width:140px" value-format="yyyy-MM-dd" placeholder="结束时间" />
        </el-form-item> -->
        <el-form-item label="单据状态">
          <el-select v-model="queryParam.qry_state" style="width:95px" clearable @change="changestate">
            <el-option v-for="item in codeModel.stateList" :key="item.code" :label="item.name" :value="item.code" clearable />
          </el-select>
        </el-form-item>
        <el-button class="filter-item" type="primary" icon="el-icon-search" @click="doQuery">搜索</el-button>
        <el-button class="filter-item" type="primary" icon="el-icon-refresh-right" @click="resetQueryParam" :disabled="isrest">重置</el-button>
      </template>
    </tl-list-search>
    <!-- 工具栏 -->
    <tl-list-toolbar ref="toolbar" @add="openAddDialog('editForm')" :isDisplayExport="false" @exportExcel="doExportExcel" @deleteBatch="doDeleteBatch" :isDisplayDeleteBatch="false" :isDisplayExportExcel="false" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="selectedRowKeys.length <= 0">
      <template slot="left-btn"> </template>
    </tl-list-toolbar>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a>项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <!-- <el-table-column type="selection" width="55px" fixed="left" :selectable="doDisableCheckBox"></el-table-column> -->
        <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
        <el-table-column prop="docno" label="单据编号" width="150px" sortable="custom" sort-by="docno" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>

        <el-table-column prop="dispprojectid" label="项目" width="200px" sortable="custom" sort-by="dispprojectid" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="changereason" label="变更原因" width="200px" sortable="custom" sort-by="changereason" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispcustomercode" label="客户名称(原)" width="120px" sortable="custom" sort-by="customercode" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispcustomercode2" label="客户名称(新)" width="120px" sortable="custom" sort-by="customercode2" align="left" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="customercode" label="客户编号(原)" width="150px" sortable="custom" sort-by="customercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="customercode2" label="客户编号(新)" width="150px" sortable="custom" sort-by="customercode2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="name" label="项目名称(原)" width="200px" sortable="custom" sort-by="name" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="name2" label="项目名称(新)" width="200px" sortable="custom" sort-by="name2" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projecttarget" label="项目目标(原)" width="200px" sortable="custom" sort-by="projecttarget" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projecttarget2" label="项目目标(新)" width="200px" sortable="custom" sort-by="projecttarget2" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="background" label="项目背景(原)" width="200px" sortable="custom" sort-by="background" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="background2" label="项目背景(新)" width="200px" sortable="custom" sort-by="background2" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispprovince" label="所属省份(原)" width="120px" sortable="custom" sort-by="province" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispprovince2" label="所属省份(新)" width="120px" sortable="custom" sort-by="province2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="ownerorgname" label="所属公司名称(原)" width="150px" sortable="custom" sort-by="ownerorgname" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="ownerorgname2" label="所属公司名称(新)" width="150px" sortable="custom" sort-by="ownerorgname2" align="left" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="ownerorgcode" label="所属公司编码(原)" width="150px" sortable="custom" sort-by="ownerorgcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="ownerorgcode2" label="所属公司编码(新)" width="150px" sortable="custom" sort-by="ownerorgcode2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="ownerdeptcode2" label="所属部门编码(新)" width="150px" sortable="custom" sort-by="ownerdeptcode2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="ownerdeptcode" label="所属部门编码(原)" width="150px" sortable="custom" sort-by="ownerdeptcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="ownerdeptname" label="所属部门名称(原)" width="150px" sortable="custom" sort-by="ownerdeptname" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="ownerdeptname2" label="所属部门名称(新)" width="150px" sortable="custom" sort-by="ownerdeptname2" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectmanagername" label="项目经理(原)" width="120px" sortable="custom" sort-by="projectmanagername" align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectmanagername2" label="项目经理(新)" width="120px" sortable="custom" sort-by="projectmanagername2" align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="projectmanagercode" label="项目经理工号(原)" width="150px" sortable="custom" sort-by="projectmanagercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="projectmanagercode2" label="项目经理工号(新)" width="150px" sortable="custom" sort-by="projectmanagercode2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="areamanagername" label="销售经理(原)" width="120px" sortable="custom" sort-by="areamanagername" align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="areamanagername2" label="销售经理(新)" width="120px" sortable="custom" sort-by="areamanagername2" align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="areamanagercode" label="销售经理工号(原)" width="150px" sortable="custom" sort-by="areamanagercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="areamanagercode2" label="销售经理工号(新)" width="150px" sortable="custom" sort-by="areamanagercode2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="reason" label="承接原因(原)" width="200px" sortable="custom" sort-by="reason" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="reason2" label="承接原因(新)" width="200px" sortable="custom" sort-by="reason2" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispcategory" label="项目类别(原)" width="120px" sortable="custom" sort-by="category" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispcategory2" label="项目类别(新)" width="120px" sortable="custom" sort-by="category2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="overview" label="项目概况(原)" width="200px" sortable="custom" sort-by="overview" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="overview2" label="项目概况(新)" width="200px" sortable="custom" sort-by="overview2" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectmoney" label="项目金额(原)" width="150px" sortable="custom" sort-by="projectmoney" align="right" :formatter="moneyFormat" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectmoney2" label="项目金额(新)" width="150px" sortable="custom" sort-by="projectmoney2" align="right" :formatter="moneyFormat" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="planstarttime" label="计划开工时间(原)" width="170px" sortable="custom" sort-by="planstarttime" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="planstarttime2" label="计划开工时间(新)" width="170px" sortable="custom" sort-by="planstarttime2" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="planendtime" label="计划完工时间(原)" width="170px" sortable="custom" sort-by="planendtime" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="planendtime2" label="计划完工时间(新)" width="170px" sortable="custom" sort-by="planendtime2" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="dispisincludeproducts" label="是否含产品(原)" width="200px" sortable="custom" sort-by="isincludeproducts" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispisincludeproducts2" label="是否含产品(新)" width="200px" sortable="custom" sort-by="isincludeproducts2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="productdetails" label="产品明细(原)" width="200px" sortable="custom" sort-by="productdetails" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="productdetails2" label="产品明细(新)" width="200px" sortable="custom" sort-by="productdetails2" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispispurchase" label="是否外包(原)" width="120px" sortable="custom" sort-by="ispurchase" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispispurchase2" label="是否外包(新)" width="120px" sortable="custom" sort-by="ispurchase2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="purchasedescription" label="外包说明(原)" width="200px" sortable="custom" sort-by="purchasedescription" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="purchasedescription2" label="外包说明(新)" width="200px" sortable="custom" sort-by="purchasedescription2" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="mandays" label="人天估算(原)" width="120px" sortable="custom" sort-by="mandays" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="mandays2" label="人天估算(新)" width="120px" sortable="custom" sort-by="mandays2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="orgname" label="申请公司" width="120px" sortable="custom" sort-by="orgname" align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="orgcode" label="申请公司编码" width="150px" sortable="custom" sort-by="orgcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="deptname" label="申请部门" width="120px" sortable="custom" sort-by="deptname" align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="deptcode" label="申请部门编码" width="150px" sortable="custom" sort-by="deptcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="usercode" label="申请人工号" width="120px" sortable="custom" sort-by="usercode" align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="username" label="申请人姓名" width="150px" sortable="custom" sort-by="username" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="docdate" label="单据日期" width="170px" sortable="custom" sort-by="docdate" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="submitdate" label="提交日期" width="170px" sortable="custom" sort-by="submitdate" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispflowid" label="审批流程" width="100px" sortable="custom" sort-by="flowid" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="latestphase" label="最新阶段" width="150px" sortable="custom" sort-by="latestphase" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispstate" label="状态" width="100px" sortable="custom" sort-by="state" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="description" label="备注" min-width="250px" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="enabled" label="有效" width="100px" sortable="custom" sort-by="enabled" align="center" header-align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.enabled === 1" type="success">是</el-tag>
            <el-tag v-else type="danger">否</el-tag>
          </template>
        </el-table-column> -->
        <!-- <el-table-column label="操作" width="220px" v-slot="scope" fixed="right">
          <el-button type="text" icon="el-icon-edit" @click="openEditDialog('editForm', scope.row.id)">编辑</el-button>
          <el-button type="text" icon="el-icon-delete" :disabled="scope.row.state !== 0 && scope.row.state !== 2" @click="doDelete(scope.row.id)">删除</el-button>
          <el-dropdown trigger="hover">
            <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu>
              <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-table-column> -->
        <el-table-column label="操作" width="100px" v-slot="scope" fixed="right">
          <el-dropdown trigger="hover">
            <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">操作<i class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu>
              <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看</el-dropdown-item>
              <el-dropdown-item icon="el-icon-edit" @click.native="openEditDialog('editForm', scope.row.id)" :disabled="scope.row.state !== 0 && scope.row.state !== 2">编辑</el-dropdown-item>
              <el-dropdown-item icon="el-icon-delete" :disabled="scope.row.state !== 0 && scope.row.state !== 2" @click.native="doDelete(scope.row.id)">删除</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-edit ref="editForm" @refresh="doRefresh"></tl-edit>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
import { checkPermission } from '@tapui/utils/permission'
/** 子组件 */
import tlEdit from './edit'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
import { rmbFormat } from '../../../utils/calculation'
export default {
  name: 'pmProjectChange',
  mixins: [mixin_list],
  components: { tlEdit },
  data() {
    return {
      description: '项目基本信息变更申请-列表查询',
      urlPrefix: '/pm/projectChange/',
      url: {
        queryCodeList: '/pm/projectChange/dataCodeList'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'sortcode',
        sord: 'asc'
      },
      isrest: false
    }
  },
  methods: {
    /** 表格双击事件 */
    doRowDbClick(row, column, event) {
      // 判断双击打开是查看还是编辑
      if (row.state === 0 || row.state === 2) {
        this.rowDbClickActionType = 'edit'
      } else {
        this.rowDbClickActionType = 'view'
      }
      if (this.rowDbClickActionType === 'edit') {
        // 判断是否有权限
        if (this.editPermission.length > 0) {
          if (checkPermission(this.editPermission)) {
            this.openEditDialog('editForm', row[this.$refs.mainTable.rowKey])
          } else {
            this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
          }
        } else {
          this.openEditDialog('editForm', row[this.$refs.mainTable.rowKey])
        }
      } else if (this.rowDbClickActionType === 'view') {
        this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
      }
    },
    changename2() {
      if (JSON.stringify(this.queryParam) !== '{}' && this.queryParam.qry_name2 !== '') {
        this.isrest = false
      } else {
        this.isrest = true
      }
    },
    changeprojectmanagername2() {
      if (JSON.stringify(this.queryParam) !== '{}' && this.queryParam.qry_projectmanagername2 !== '') {
        this.isrest = false
      } else {
        this.isrest = true
      }
    },
    changedocno() {
      if (JSON.stringify(this.queryParam) !== '{}' && this.queryParam.qry_docno !== '') {
        this.isrest = false
      } else {
        this.isrest = true
      }
    },
    changestate() {
      if (JSON.stringify(this.queryParam) !== '{}' && this.queryParam.qry_state !== '') {
        this.isrest = false
      } else {
        this.isrest = true
      }
    },
    afterLoadData() {
      this.isrest = false
      if (JSON.stringify(this.queryParam) === '{}') {
        this.isrest = true
      }
    },
    // 禁用表格前面的选择
    doDisableCheckBox(row, index) {
      if (row.state !== 0 && row.state !== 2) {
        return false
      } else {
        return true
      }
    },
    resetQueryParam() {
      this.queryParam = {}
      this.changename2()
      this.changeprojectmanagername2()
      this.changedocno()
      this.changestate()
    },
    moneyFormat(row, column, cellValue, index) {
      return rmbFormat(row[column.property])
    }
  }
}
</script>

<style scoped></style>

